<?php
function getItemDetails($id)
{
	$dirHandle = opendir("textfiles/");
	$filesArray = array();
	while (false !== ($file = readdir($dirHandle)))
	{
		if (strstr($file, '.txt'))
		{
			$filesArray[] = $file;
		}
	}
	$counter = 0;
	foreach ($filesArray as $file)
	{
		$filename = "textfiles/" . $file;
		$fd = fopen ($filename, "r");
		$contents = fread ($fd, filesize ($filename));
		fclose ($fd);
		$splitcontents = explode ("\n", $contents);
		
		foreach ($splitcontents as $value)
		{
			$items[$counter] = explode ("|", $value);
			$counter++;
		}
	}
	foreach ($items as $value)
	{
		
		if($value[0] == $id)
		{
			return $value;
		}
	}
	return "Error: 404 Item Not Found.";
}
?>